<template>
  <div id="app">
 
 <transition :name="transitionName">
    <router-view class="router-view" />
</transition>
  </div>
</template>

<script>
// 移动端点击事件`click`不生效,需要使用`fastclick`插件解决
import FastClick from 'fastclick'

export default {
    // 监听路由的路径，可以通过不同的路径去选择不同的切换效果
    data() {
        return {
            transitionName: 'slide-left'
        }
    },
      created() {
    // 处理页面刷新之后的状态
    console.log('=========> 初次加载 <=================');
    // 判断 用户是否登录
    if (this.$store.getters.getIsLogin) {
      // 已登录 刷新之后 获取用户信息
      this.$store.dispatch('getInfo')
      this.$store.dispatch('getCartData')
    }

    },
    // 监听路由的路径，可以通过不同的路径去选择不同的切换效果
    watch: {
        $route(to, from) {
            if (to.meta.index > from.meta.index) { //外---》内
                this.transitionName = 'slide-left'
            } else if (to.meta.index < from.meta.index) { //内---》外
                this.transitionName = 'slide-right'
            } else {
                this.transitionName = '' //同级 无过渡效果
            }
        }
    },
     mounted() {
    //解决移动端点击300ms延时
    FastClick.attach(document.body);
  }
}
</script>


<style lang="scss">
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}

/*切换样式出错处理*/
.router-view {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    bottom: 0;
    margin: 0 auto;
    -webkit-overflow-scrolling: touch;
}

/*切换动画*/
.slide-right-enter-active,
.slide-right-leave-active,
.slide-left-enter-active,
.slide-left-leave-active {
    height: 100%;
    will-change: transform;
    transition: all 500ms;
    position: absolute;
    backface-visibility: hidden;
}

.slide-right-enter {
    opacity: 0;
    transform: translate3d(-100%, 0, 0);
}

.slide-right-leave-active {
    opacity: 0;
    transform: translate3d(100%, 0, 0);
}

.slide-left-enter {
    opacity: 0;
    transform: translate3d(100%, 0, 0);
}

.slide-left-leave-active {
    opacity: 0;
    transform: translate3d(-100%, 0, 0);
}
</style>
